home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.02 Feb 93 / Date FKEY / DateFKEY.p < prev    next >
Encoding:
Text File  |  1992-08-16  |  1.9 KB  |  83 lines  |  [TEXT/PJMM]

  1. unit DateFKEY;
  2.  
  3.     { Types the current date when the user types cmd-shift-6. }
  4.  
  5. interface
  6.  
  7.     procedure main;
  8.  
  9. implementation
  10.  
  11.     procedure main;
  12.  
  13.  { ----------------------------- }
  14.  
  15.         function SendAString (theStr: str255): OSErr;
  16.             const
  17.             { keyMap is a subset of the KCHR System resource. }
  18.                 keyMap = 'ASDFHGZXCV*BQWERYT123465=97*80*OU*IP*LJ*K**,*NM';
  19.                 space = char(32);
  20.             var
  21.                 i, keyCode: integer;
  22.                 theChar: char;
  23.                 theErr: OSErr;
  24.                 message, modifiers, modifierMask: longint;
  25.                 myQPtr: EvQElPtr;
  26.         begin
  27.             theErr := noErr;
  28.             modifierMask := BitNot(shiftKey + cmdKey);
  29.  
  30.             if theStr <> '' then
  31.                 begin
  32.                     FlushEvents(keyDown, 0);
  33.                     for i := 1 to length(theStr) do
  34.                         begin
  35.  
  36.                         { Get the proper keyCode from our keyMap. }
  37.                             theChar := theStr[i];
  38.                             if theChar in ['a'..'z'] then    { Make theChar uppercase for our look-up string. }
  39.                                 theChar := char(ord(theChar) - 32);
  40.                             if theChar = space then
  41.                                 keyCode := $31
  42.                             else
  43.                                 keyCode := pos(theChar, keyMap) - 1;
  44.                             if keyCode = -1 then
  45.                                 keyCode := 0;
  46.  
  47.                         { Assemble the message. }
  48.                             message := BitShift(keyCode, 8) + ord(theStr[i]);
  49.  
  50.                         { Post the keyDown event. }
  51.                             theErr := PPostEvent(keyDown, message, myQPtr);
  52.                             if theErr <> noErr then
  53.                                 leave;
  54.  
  55.                         { Now strip off the cmdKey and shiftKey modifiers. }
  56.                             modifiers := BitAnd(myQPtr^.evtQModifiers, modifierMask);
  57.                             myQPtr^.evtQModifiers := modifiers;
  58.                         end;
  59.                 end;
  60.             SendAString := theErr;
  61.         end;
  62.  
  63.  { ============== main ============== }
  64.  
  65.         var
  66.             dateStr: str255;
  67.             tempLong: longint;
  68.     begin
  69.  
  70.     { The queue can only hold 20 characters, }
  71.     { so we strip off the day of the week.   }
  72.  
  73.         GetDateTime(tempLong);
  74.         IUDateString(tempLong, LongDate, dateStr);
  75.         if dateStr <> '' then
  76.             if pos(char(32), dateStr) > 0 then
  77.                 Delete(dateStr, 1, pos(char(32), dateStr));
  78.  
  79.         if SendAString(dateStr) <> noErr then
  80.             SysBeep(10);
  81.     end;
  82.  
  83. end.